<?php
header("Content-Type:text/html;charset=utf-8");
require_once "config.php";
    if($_SERVER['REQUEST_METHOD'] == 'POST'){
        // 120.678797,31.318784
        // $lat = 31.318784;
        // $lng = 120.678797;
        $lat = $_POST['lat'];
        $lng = $_POST['lng'];
        if(empty($lat) || empty($lng)){
            $result['status'] = 'n';
    		$result['info'] = '数据为空，请重新提交';
            exit(json_encode($result));
        }

        $range  = 180 / pi() / 6372.797 * 0.5; //里面的 $kilometers 就代表搜索 km 之内，单位km
        $lngR   = $range / cos($lat * pi() / 180);
        $maxLat = $lat + $range; //最大纬度
        $minLat = $lat - $range; //最小纬度
        $maxLng = $lng + $lngR; //最大经度
        $minLng = $lng - $lngR; //最小经度
        // echo $maxLat.'  '.$minLat.'  '.$maxLng.'  '.$minLng;exit;
        // // 31.326795340077  31.317804659923  120.65152228333  120.64099771667
        // $mysql=new MySqli('121.40.126.186', 'fyh5p8_fyh51_co', 'KZa3YTBZnMTS3JeQ','fyh5p8_fyh51_co');
        $sql="select * from dyspw_member where shop_lat>$minLat AND shop_lat<$maxLat AND shop_lng>$minLng AND shop_lng<$maxLng";
        $loca_shop = mysqli_query($mysql, $sql);
        $loca_shop = $loca_shop->fetch_all(MYSQLI_ASSOC);
        if(!empty($loca_shop)){
            $result['status'] = 'y';
    		$result['data'] = $loca_shop;
            exit(json_encode($result));
        }else{
            $result['status'] = 'n';
    		$result['info'] = '未查询到信息';
            exit(json_encode($result));
        }

    }
